#ifndef  _INTERRUPT_H_
#define _INTERRUPT_H_

#include "base.h"
#include "ipc.h"
#include "syscall.h"

/*****************************************/
/*                                       */
/*  interrupt vector and prototype       */
/*                                       */
/*****************************************/

#define DIVIDE_ERR		0
#define DEBUG_ERR		1
#define NMI				2
#define BREAKPOINT		3
#define OVERFLOW		4
#define BOUNDARY_RANGE	5
#define UNDEF_OP		6
#define NON_MATH		7
#define DOUBLE_FAULT	8
#define SEG_OVERRUN		9
#define INVALID_TSS		10
#define SEG_NOT_PRE		11
#define STACK_FAULE		12
#define GENERAL_PROT	13
#define PAGE_FAULT		14
#define RESERVED		15
#define FLOAT_ERR		16
#define ALIGN_CHECK		17
#define MACHINE_CHECK	18
#define SIMD_EXCEPTION	19

/* 20 ~ 31 reserved */
#define CLOCK			32
#define KEEBOARD			33
#define SERIAL			34

#define IPC				63
#define SYSCALL			64

#define TEST			65
#define INTR_MAX		(TEST + 1)

int divide_err(void);
int debug_err(void);
int nmi(void);
int breakpoint(void);
int overflow(void);
int boundary_err(void);
int invalid_operation(void);
int device_not_avail(void);
int double_fault(void);
int seg_overrun(void);
int invalid_tss(void);
int seg_not_present(void);
int stack_fault(void);
int general_protection(void);
int page_fault(void);
int float_err(void);
int alignment_check(void);
int machine_check(void);
int simd_exception(void);
int clock(void);
int keyboard(void);
int serial(void);
int ipc(void);
int syscall(void);

/* RPL in selector within gate descriptor */
#define KERN_PRIV		0
#define USER_PRIV		3

typedef int (*intr_hook_t)(void);

struct _intr_handler{
	uint_32 intr_vector;
	intr_hook_t intr_hook;
	uint_32 priv;
	uint_32 type;
};

EXTERN struct _intr_handler  intr_handler_array[];

static inline int disable_intr(void){
	__asm__(" cli;	\n\t");

	return 0;
};

static inline int enable_intr(void){
	__asm__(" sti;	\n\t");

	return 0;
};



struct syscall_handler_t{
	int sys_call_nr;
	int (*do_sys)(struct syscall_t *sys);
};


extern struct syscall_handler_t sys_call_table[];

/**************************************************/
/*                                                */
/*  syscall function and prototype                */
/*                                                */
/**************************************************/
int do_cur_proc(struct syscall_t *syscall_p);
int do_fork(struct syscall_t *syscall_p);
int do_kill(struct syscall_t *syscall_p);
int do_suspend(struct syscall_t *syscall_p);
int do_exit(struct syscall_t *syscall_p);
int do_exec(struct syscall_t *syscall_p);
int do_timer(struct syscall_t *syscall_p);
int do_sleep(struct syscall_t *syscall_p);
int do_read(struct syscall_t *syscall_p);
int do_write(struct syscall_t *syscall_p);
int do_new_mem(struct syscall_t *syscall_p);
int do_malloc(struct syscall_t *syscall_p);
int do_free(struct syscall_t *syscall_p);
int do_print(struct syscall_t *syscall_p);
#endif

